<?
if (!defined('MODULE_FILE')){
die ("cant access file directly!");
}
$mid2=$_GET['mid'];
require_once 'class/NewModule.php';
?>
<?
if(isset($_POST['Submit']))
{
	$total = $_POST['total'];
	$td = 0;
	$i = 0;
	for($i = 1; $i <= $total; $i++)
	{
		if(isset($_POST["d$i"]))
		{
		$mid01=$_POST["d$i"];
		$result_chk = mysql_query("SELECT * FROM `menu` where parent='$mid01' order by rank");//var_dump($result_chk);
		$row_chk = mysql_fetch_array($result_chk, MYSQL_BOTH); 	
		$num=mysql_num_rows($result_chk);
		if($num>0)
		{
			?>
				<script langauge="javascript">
				var msg="Delete Sub menu first";
				alert(msg)</script>
			<?	
		}
		else
		{
		
		mysql_query("DELETE FROM menu WHERE mid=".$_POST["d$i"]);
		$td++;
		}
		}
	}	
}
?>
<?
$att = new NewModule();
$result = $att->AllList();
$n = 0;
?>
	<div style="margin-left:20px; margin-top: 10px;">
		<p>
			<a href="modules.php?file=module_add&mid=<? echo $mid;?>&smid=<? echo $smid;?>" id="active" class="btn btn-outline btn-primary btn-xs">Add Module</a>
		</p>
	</div>
	
	<div class="col-lg-6">
		<div class="panel panel-primary">
			<div class="panel-heading"><i class="fa fa-bell fa-fw"></i>List Modules</div>
			
			<div class="panel-body">
						
	<form name="form12" id ="cbexample" method="post" action="">
		<table class="formcss">	
		<?
		for ($i = 0; $i < count($result); $i++)
		{
		$n++;
		$mid11=$result[$i]['mid'];
        ?>
		<tr>   
		<td width=30%>
		<input type="checkbox" name="d<?php echo $n;?>" value="<?php echo $result[$i]['mid'];?>">
		<a class='vsmenu' href='modules.php?file=module_details&mid2=<? echo $result[$i]['mid'];?>&mid=<? echo $mid2; ?>&smid=<? echo $smid;?>&parent=<? echo $result[$i]['parent'];?>'><font size=2><b><?echo $result[$i]['title']; ?>&nbsp;</b></font></a>(<?echo $result[$i]['rank'];?>)
		<?	echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		?>
		</td> 
		</tr>
		<?
		$result1 = $att->AllList1($mid11);
		for ($j = 0; $j < count($result1); $j++)
		{
		$n++;
		$mid1=$result1[$j]['mid'];
		$parent=$result1[$j]['parent'];
		?>
		<tr>
		<td ><?  echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp";?>
			<input type="checkbox" name="d<?php echo $n;?>" value="<?php echo $result1[$j]['mid'];?>">
			<a class='vsmenu' href='modules.php?file=module_details&mid2=<? echo $result1[$j]['mid'];?>&mid=<? echo $mid2; ?>&smid=<? echo $smid;?>&parent=<? echo $result1[$j]['parent'];?>'><? echo $result1[$j]['title'];?>&nbsp;</a>(<?echo $result1[$j]['rank'];?>)
		</td> 
		</tr>	
		<?	
		$result2 = $att->AllList1($mid1);
		for ($k = 0; $k < count($result2); $k++)
		{
		$n++;
		?>
		<tr>   
		<td ><?echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";?>
				<input type="checkbox" name="d<?php echo $n;?>" value="<?php echo $result2[$k]['mid'];?>">
				<a class='vsmenu' href='modules.php?file=module_details&mid2=<? echo $result2[$k]['mid'];?>&mid=<? echo $mid2;?>&smid=<? echo $smid;?>&parent=<? echo $result2[$k]['parent'];?>'><? echo $result2[$k]['title'];?>&nbsp;</a>(<?echo $result2[$k]['rank'];?>)
			
		</td> 
		</tr>
		<?
		}		
	}	
}
?>
<tr>        
<td>
<input type='checkbox' name='checkall' onclick='checkedAll("cbexample");'>&nbsp;<b>Select All</b>
<input type="Submit" class="table-button" name="Submit" value="Delete" onclick='return confirmSubmit();'/>
<input name="total" type="hidden" id="total" value="<?php echo $n?>">
</td>     
</tr>
</table>
</form>
</div>
</div>
</div>